** Extract variables from topical modules
**
** Health and certain financial well-being variables
** Grandparent status and total number of kids (including those living elsewhere) from fertility history modules


********************************************************************************

********************************************
********************************************
** CHILDCARE VARIABLES
********************************************
********************************************


*******************
** 1990, Wave 3
*******************
quietly infile using sip90t3.dct,  using (s90w3tm.dat)
destring pnum, replace

gen GetCCFromGP = (tm8120==3 | tm8122==3 | tm8124==3 | tm8170==3 | tm8172==3 | tm8174==3)

keep id entry pnum GetCCFromGP 

rename id suid 
tostring suid, replace

save ChildCareVars_1990_w3, replace
clear


*******************
** 1991, Wave 3
*******************
quietly infile using sip91t3.dct,  using (sipp91t3.dat)
destring pnum, replace

gen GetCCFromGP = (tm8120==3 | tm8122==3 | tm8124==3 | tm8170==3 | tm8172==3 | tm8174==3)

keep id entry pnum GetCCFromGP 

rename id suid 
tostring suid, replace

save ChildCareVars_1991_w3, replace
clear


*******************
** 1992, Wave 6
*******************
quietly infile using sip92t6.dct,  using (sipp92t6.dat)
destring pnum, replace

gen GetCCFromGP = (tm8120==3 | tm8122==3 | tm8124==3 | tm8170==3 | tm8172==3 | tm8174==3)

keep id entry pnum GetCCFromGP 

rename id suid 
tostring suid, replace

save ChildCareVars_1992_w6, replace
clear


*******************
** 1993, Wave 3
*******************
quietly infile using sip93t3.dct,  using (sipp93t3.dat)
destring pnum, replace

gen GetCCFromGP = (tm8120==3 | tm8122==3 | tm8124==3 | tm8170==3 | tm8172==3 | tm8174==3)

keep id entry pnum GetCCFromGP 

rename id suid 
tostring suid, replace

save ChildCareVars_1993_w3, replace
clear



*******************
** 1993, Wave 6
*******************
quietly infile using sip93t6.dct,  using (sipp93t6.dat)
destring pnum, replace

gen GetCCFromGP = (tm8120==3 | tm8122==3 | tm8124==3 | tm8170==3 | tm8172==3 | tm8174==3)

keep id entry pnum GetCCFromGP 

rename id suid 
tostring suid, replace

save ChildCareVars_1993_w6, replace
clear



*******************
** 1996, Wave 4
*******************
quietly infile using sip96t4.dct,  using (sipp96t4.dat)
destring epppnum, replace

gen GetCCFromGP = (eckd05a==1 | eckd05b==1 | eckd05c==1 | eckd05d==1 | eckd05e==1 | eckd05f==1 | eckd05g==1 |  eckd05h==1 | eckd05i==1 | eckd05j==1)   

gen PayForCCFromGP = (epaygraa==1 | epaygrab==1 | epaygrac==1 | epaygrad==1 | epaygrae==1 | epaygraf==1 | epaygrag==1 |  epaygrah==1 | epaygrai==1 | epaygraj==1)   

keep ssuid epppnum GetCCFromGP PayForCCFromGP

save ChildCareVars_1996_w4, replace
clear



*******************
** 1996, Wave 10
*******************
quietly infile using sip96t10.dct,  using (sipp96t10.dat)
destring epppnum, replace

gen GetCCFromGP = (eckd05a==1 | eckd05b==1 | eckd05c==1 | eckd05d==1 | eckd05e==1 | eckd05f==1 | eckd05g==1 |  eckd05h==1 | eckd05i==1 | eckd05j==1)   

gen PayForCCFromGP = (epaygraa==1 | epaygrab==1 | epaygrac==1 | epaygrad==1 | epaygrae==1 | epaygraf==1 | epaygrag==1 |  epaygrah==1 | epaygrai==1 | epaygraj==1)   

keep ssuid epppnum GetCCFromGP PayForCCFromGP

save ChildCareVars_1996_w10, replace
clear



*******************
** 2001, Wave 4
*******************
quietly infile using sip01t4.dct,  using (sipp01t4.dat)
destring epppnum, replace

gen GetCCFromGP = (eckd05a==1 | eckd05b==1 | eckd05c==1 | eckd05d==1 | eckd05e==1 | eckd05f==1 | eckd05g==1 |  eckd05h==1 | eckd05i==1 | eckd05j==1)   

gen PayForCCFromGP = (epaygraa==1 | epaygrab==1 | epaygrac==1 | epaygrad==1 | epaygrae==1 | epaygraf==1 | epaygrag==1 |  epaygrah==1 | epaygrai==1 | epaygraj==1)   

keep ssuid epppnum GetCCFromGP PayForCCFromGP

save ChildCareVars_2001_w4, replace
clear




*******************
** 2004, Wave 4
*******************

quietly infile using sip04t4.dct,  using (p04putm4.dat)
destring epppnum, replace

gen GetCCFromGP = (eckd05a==1 | eckd05b==1 | eckd05c==1 | eckd05d==1 | eckd05e==1 | eckd05f==1 | eckd05g==1 |  eckd05h==1 | eckd05i==1 | eckd05j==1)   

gen PayForCCFromGP = (epaygraa==1 | epaygrab==1 | epaygrac==1 | epaygrad==1 | epaygrae==1 | epaygraf==1 | epaygrag==1 |  epaygrah==1 | epaygrai==1 | epaygraj==1)   

keep ssuid epppnum GetCCFromGP PayForCCFromGP

save ChildCareVars_2004_w4, replace
clear




*******************
** 2008, Wave 5
*******************

quietly infile using sippp08putm5.dct,  using (p08putm5.dat)
destring epppnum, replace

gen GetCCFromGP = (eckd05a==1 | eckd05b==1 | eckd05c==1 | eckd05d==1 | eckd05e==1 | eckd05f==1 | eckd05g==1 |  eckd05h==1 | eckd05i==1 | eckd05j==1)   

gen PayForCCFromGP = (epaygraa==1 | epaygrab==1 | epaygrac==1 | epaygrad==1 | epaygrae==1 | epaygraf==1 | epaygrag==1 |  epaygrah==1 | epaygrai==1 | epaygraj==1)   

keep ssuid epppnum GetCCFromGP PayForCCFromGP

save ChildCareVars_2008_w5, replace
clear




*******************
** 2008, Wave 8
*******************

quietly infile using sippp08putm8.dct,  using (p08putm8.dat)
destring epppnum, replace

gen GetCCFromGP = (eckd05a==1 | eckd05b==1 | eckd05c==1 | eckd05d==1 | eckd05e==1 | eckd05f==1 | eckd05g==1 |  eckd05h==1 | eckd05i==1 | eckd05j==1)   

gen PayForCCFromGP = (epaygraa==1 | epaygrab==1 | epaygrac==1 | epaygrad==1 | epaygrae==1 | epaygraf==1 | epaygrag==1 |  epaygrah==1 | epaygrai==1 | epaygraj==1)   

keep ssuid epppnum GetCCFromGP PayForCCFromGP

save ChildCareVars_2008_w8, replace
clear






**********************
** 2014, Wave 1
**********************

use ssuid pnum spanel swave monthcode tage egran rgran using pu2014w1.dta
** NOTE: egran is for ref parents, ages 15 and older. rgran is for grandkids (age<15).


gen GetCCFromGP = (egran==1)

save ChildCareVars_2014_w1, replace
clear


**********************
** 2014, Wave 2
**********************

use ssuid pnum spanel swave monthcode tage egran rgran using pu2014w2.dta

gen GetCCFromGP = (egran==1 )

save ChildCareVars_2014_w2, replace
clear



**********************
** 2014, Wave 3
**********************

use ssuid pnum spanel swave monthcode tage egran rgran using pu2014w3_13.dta

gen GetCCFromGP = (egran==1 )

save ChildCareVars_2014_w3, replace
clear


**********************
** 2014, Wave 4
**********************

use ssuid pnum spanel swave monthcode tage egran rgran using pu2014w4.dta

gen GetCCFromGP = (egran==1 )

save ChildCareVars_2014_w4, replace
clear




********************************************
********************************************
** WELL-BEING VARIABLES: HEALTH AND DEBT
********************************************
********************************************




********************************************
*************
** 1990
*************
********************************************



*****************************
** Wave 3, Health Variables
*****************************
quietly infile using sip90t3.dct, using(s90w3tm.dat)
destring pnum, replace

keep id entry pnum tm8800

gen PoorHealth=(tm8800==5)
replace PoorHealth=. if tm8800==0
gen ExcellentHealth=(tm8800==1)
replace ExcellentHealth=. if tm8800==0

rename tm8800 ehltstat
rename id suid 
tostring suid, replace

save WellBeingVars1990_w3, replace
clear



*****************************
** Wave 4, Debt Variables
*****************************


quietly infile using sip90t4.dct, using(s90w4tm.dat)
destring pnum, replace
* Reminder: id entry uniquely identify households in this dataset

** Dealing with jointly-owned assets is a bit tricker in 1992 panel than in later panels.
** Only one spouse's record contains the data on tm8212, tm8214, etc. The other spouse's
** record is blank.  To match what you do in later years, should add up values across the
** two spouses and divide equally.

gen temp_had_ccdebt_joint = (tm8212==1)
gen temp_amt_ccdebt_joint = tm8214
gen temp_had_bankloan_joint = (tm8216==1)
gen temp_amt_bankloan_joint = tm8218 
gen temp_had_otherdebt_joint = (tm8220==1)
gen temp_amt_otherdebt_joint = tm8222 

gen temp_had_checking_joint = (tm8209==1)
gen temp_amt_checking_joint = tm8210
replace temp_amt_checking_joint = 0 if tm8210==-3

gen temp_amt_intbear_joint = sc4314
replace temp_amt_intbear_joint = 0 if sc4314==-3

keep id entry pnum pnsp temp_had_ccdebt_joint temp_amt_ccdebt_joint temp_had_bankloan_joint temp_amt_bankloan_joint temp_had_otherdebt_joint temp_amt_otherdebt_joint temp_had_checking_joint temp_amt_checking_joint temp_amt_intbear_joint
drop pnsp
rename pnum pnsp
rename temp_had_ccdebt_joint sp_had_ccdebt_joint 
rename temp_amt_ccdebt_joint sp_amt_ccdebt_joint
rename temp_had_bankloan_joint sp_had_bankloan_joint
rename temp_amt_bankloan_joint sp_amt_bankloan_joint
rename temp_had_otherdebt_joint sp_had_otherdebt_joint
rename temp_amt_otherdebt_joint sp_amt_otherdebt_joint
rename temp_had_checking_joint sp_had_checking_joint
rename temp_amt_checking_joint sp_amt_checking_joint
rename temp_amt_intbear_joint sp_amt_intbear_joint

save temp, replace
clear

quietly infile using sip90t4.dct, using(s90w4tm.dat)
destring pnum, replace

merge m:1 id entry pnsp using temp
drop if _merge==2

gen had_ccdebt_joint = (tm8212==1 | sp_had_ccdebt_joint==1)
egen amt_ccdebt_joint = rowmean(tm8214 sp_amt_ccdebt_joint)
gen had_bankloan_joint = (tm8216==1 | sp_had_bankloan_joint==1)
egen amt_bankloan_joint = rowmean(tm8218 sp_amt_bankloan_joint) 
gen had_otherdebt_joint = (tm8220==1 | sp_had_otherdebt_joint==1)
egen amt_otherdebt_joint = rowmean(tm8222  sp_amt_otherdebt_joint)

recode tm8210 -3=0
gen had_checking_joint = (tm8209==1 |sp_had_checking_joint==1)
egen amt_checking_joint = rowmean(tm8210  sp_amt_checking_joint)

recode sc4314 -3=0
egen amt_intbear_joint = rowmean(sc4314 sp_amt_intbear_joint)

gen had_ccdebt_own =(tm8236 ==1)
gen amt_ccdebt_own = tm8238
gen had_bankloan_own = (tm8240==1)
gen amt_bankloan_own = tm8242
gen had_otherdebt_own = (tm8244==1)
gen amt_otherdebt_own = tm8246 

gen had_checking_own = (tm8232==1)
gen amt_checking_own = tm8233
replace amt_checking_own = 0 if tm8233==-3

gen amt_intbear_own = sc4322
replace amt_intbear_own = 0 if sc4322==-3

rename id suid 
tostring suid, replace

keep suid entry pnum  had_* amt_* 

gen AnyDebt = (had_ccdebt_joint==1 | had_bankloan_joint==1 | had_otherdebt_joint==1 | had_ccdebt_own | had_bankloan_own | had_otherdebt_own)
egen DebtAmount = rowtotal(amt_ccdebt_joint amt_bankloan_joint amt_otherdebt_joint amt_ccdebt_own amt_bankloan_own amt_otherdebt_own)
gen AnyCCDebt=(had_ccdebt_joint==1 | had_ccdebt_own==1)
egen CCDebtAmount = rowtotal(amt_ccdebt_joint amt_ccdebt_own)

gen AnyChecking = (had_checking_joint==1 | had_checking_own==1)
egen CheckingAmount = rowtotal(amt_checking_joint amt_checking_own)

egen IntBearAmount = rowtotal (amt_intbear_joint amt_intbear_own)

save WellBeingVars1990_w4, replace
clear




********************************************
*************
** 1991
*************
********************************************



*****************************
** Wave 3, Health Variables
*****************************
quietly infile using sip91t3.dct, using(sipp91t3.dat)
destring pnum, replace

keep id entry pnum tm8800

gen PoorHealth=(tm8800==5)
replace PoorHealth=. if tm8800==0
gen ExcellentHealth=(tm8800==1)
replace ExcellentHealth=. if tm8800==0

rename tm8800 ehltstat
rename id suid 
tostring suid, replace

save WellBeingVars1991_w3, replace
clear




*****************************
** Wave 7, Debt Variables
*****************************


quietly infile using sip91t7.dct, using(sipp91t7.dat)
destring pnum, replace
* Reminder: id entry uniquely identify households in this dataset

** Dealing with jointly-owned assets is a bit tricker in 1992 panel than in later panels.
** Only one spouse's record contains the data on tm8212, tm8214, etc. The other spouse's
** record is blank.  To match what you do in later years, should add up values across the
** two spouses and divide equally.

gen temp_had_ccdebt_joint = (tm8212==1)
gen temp_amt_ccdebt_joint = tm8214
gen temp_had_bankloan_joint = (tm8216==1)
gen temp_amt_bankloan_joint = tm8218 
gen temp_had_otherdebt_joint = (tm8220==1)
gen temp_amt_otherdebt_joint = tm8222 

gen temp_had_checking_joint = (tm8209==1)
gen temp_amt_checking_joint = tm8210
replace temp_amt_checking_joint = 0 if tm8210==-3

gen temp_amt_intbear_joint = tm4314
replace temp_amt_intbear_joint = 0 if tm4314==-3

keep id entry pnum pnsp temp_had_ccdebt_joint temp_amt_ccdebt_joint temp_had_bankloan_joint temp_amt_bankloan_joint temp_had_otherdebt_joint temp_amt_otherdebt_joint temp_had_checking_joint temp_amt_checking_joint temp_amt_intbear_joint
drop pnsp
rename pnum pnsp
rename temp_had_ccdebt_joint sp_had_ccdebt_joint 
rename temp_amt_ccdebt_joint sp_amt_ccdebt_joint
rename temp_had_bankloan_joint sp_had_bankloan_joint
rename temp_amt_bankloan_joint sp_amt_bankloan_joint
rename temp_had_otherdebt_joint sp_had_otherdebt_joint
rename temp_amt_otherdebt_joint sp_amt_otherdebt_joint
rename temp_had_checking_joint sp_had_checking_joint
rename temp_amt_checking_joint sp_amt_checking_joint
rename temp_amt_intbear_joint sp_amt_intbear_joint

save temp, replace
clear

quietly infile using sip91t7.dct, using(sipp91t7.dat)
destring pnum, replace

merge m:1 id entry pnsp using temp
drop if _merge==2

gen had_ccdebt_joint = (tm8212==1 | sp_had_ccdebt_joint==1)
egen amt_ccdebt_joint = rowmean(tm8214 sp_amt_ccdebt_joint)
gen had_bankloan_joint = (tm8216==1 | sp_had_bankloan_joint==1)
egen amt_bankloan_joint = rowmean(tm8218 sp_amt_bankloan_joint) 
gen had_otherdebt_joint = (tm8220==1 | sp_had_otherdebt_joint==1)
egen amt_otherdebt_joint = rowmean(tm8222  sp_amt_otherdebt_joint)

recode tm8210 -3=0
gen had_checking_joint = (tm8209==1 |sp_had_checking_joint==1)
egen amt_checking_joint = rowmean(tm8210  sp_amt_checking_joint)

recode tm4314 -3=0
egen amt_intbear_joint = rowmean(tm4314 sp_amt_intbear_joint)

gen had_ccdebt_own =(tm8236 ==1)
gen amt_ccdebt_own = tm8238
gen had_bankloan_own = (tm8240==1)
gen amt_bankloan_own = tm8242
gen had_otherdebt_own = (tm8244==1)
gen amt_otherdebt_own = tm8246 

gen had_checking_own = (tm8232==1)
gen amt_checking_own = tm8233
replace amt_checking_own = 0 if tm8233==-3

gen amt_intbear_own = tm4322
replace amt_intbear_own = 0 if tm4322==-3

rename id suid 
tostring suid, replace

keep suid entry pnum  had_* amt_* 

gen AnyDebt = (had_ccdebt_joint==1 | had_bankloan_joint==1 | had_otherdebt_joint==1 | had_ccdebt_own | had_bankloan_own | had_otherdebt_own)
egen DebtAmount = rowtotal(amt_ccdebt_joint amt_bankloan_joint amt_otherdebt_joint amt_ccdebt_own amt_bankloan_own amt_otherdebt_own)
gen AnyCCDebt=(had_ccdebt_joint==1 | had_ccdebt_own==1)
egen CCDebtAmount = rowtotal(amt_ccdebt_joint amt_ccdebt_own)

gen AnyChecking = (had_checking_joint==1 | had_checking_own==1)
egen CheckingAmount = rowtotal(amt_checking_joint amt_checking_own)

egen IntBearAmount = rowtotal (amt_intbear_joint amt_intbear_own)

save WellBeingVars1991_w7, replace
clear



********************************************
*************
** 1992
*************
********************************************

*****************************
** Wave 4, Debt Variables
*****************************


quietly infile sip92t4.dct, using(sipp92t4.dat)
destring pnum, replace
* Reminder: id entry uniquely identify households in this dataset

** Dealing with jointly-owned assets is a bit tricker in 1992 panel than in later panels.
** Only one spouse's record contains the data on tm8212, tm8214, etc. The other spouse's
** record is blank.  To match what you do in later years, should add up values across the
** two spouses and divide equally.

gen temp_had_ccdebt_joint = (tm8212==1)
gen temp_amt_ccdebt_joint = tm8214
gen temp_had_bankloan_joint = (tm8216==1)
gen temp_amt_bankloan_joint = tm8218 
gen temp_had_otherdebt_joint = (tm8220==1)
gen temp_amt_otherdebt_joint = tm8222 

gen temp_had_checking_joint = (tm8209==1)
gen temp_amt_checking_joint = tm8210
replace temp_amt_checking_joint = 0 if tm8210==-3

gen temp_amt_intbear_joint = tm4314
replace temp_amt_intbear_joint = 0 if tm4314==-3

keep id entry pnum pnsp temp_had_ccdebt_joint temp_amt_ccdebt_joint temp_had_bankloan_joint temp_amt_bankloan_joint temp_had_otherdebt_joint temp_amt_otherdebt_joint temp_had_checking_joint temp_amt_checking_joint temp_amt_intbear_joint
drop pnsp
rename pnum pnsp
rename temp_had_ccdebt_joint sp_had_ccdebt_joint 
rename temp_amt_ccdebt_joint sp_amt_ccdebt_joint
rename temp_had_bankloan_joint sp_had_bankloan_joint
rename temp_amt_bankloan_joint sp_amt_bankloan_joint
rename temp_had_otherdebt_joint sp_had_otherdebt_joint
rename temp_amt_otherdebt_joint sp_amt_otherdebt_joint
rename temp_had_checking_joint sp_had_checking_joint
rename temp_amt_checking_joint sp_amt_checking_joint
rename temp_amt_intbear_joint sp_amt_intbear_joint

save temp, replace
clear

quietly infile using sip92t4.dct, using(sipp92t4.dat)
destring pnum, replace

merge m:1 id entry pnsp using temp
drop if _merge==2

gen had_ccdebt_joint = (tm8212==1 | sp_had_ccdebt_joint==1)
egen amt_ccdebt_joint = rowmean(tm8214 sp_amt_ccdebt_joint)
gen had_bankloan_joint = (tm8216==1 | sp_had_bankloan_joint==1)
egen amt_bankloan_joint = rowmean(tm8218 sp_amt_bankloan_joint) 
gen had_otherdebt_joint = (tm8220==1 | sp_had_otherdebt_joint==1)
egen amt_otherdebt_joint = rowmean(tm8222  sp_amt_otherdebt_joint)

recode tm8210 -3=0
gen had_checking_joint = (tm8209==1 |sp_had_checking_joint==1)
egen amt_checking_joint = rowmean(tm8210  sp_amt_checking_joint)

recode tm4314 -3=0
egen amt_intbear_joint = rowmean(tm4314 sp_amt_intbear_joint)

gen had_ccdebt_own =(tm8236 ==1)
gen amt_ccdebt_own = tm8238
gen had_bankloan_own = (tm8240==1)
gen amt_bankloan_own = tm8242
gen had_otherdebt_own = (tm8244==1)
gen amt_otherdebt_own = tm8246 

gen had_checking_own = (tm8232==1)
gen amt_checking_own = tm8233
replace amt_checking_own = 0 if tm8233==-3

gen amt_intbear_own = tm4322
replace amt_intbear_own = 0 if tm4322==-3

rename id suid 
tostring suid, replace

keep suid entry pnum  had_* amt_* 

gen AnyDebt = (had_ccdebt_joint==1 | had_bankloan_joint==1 | had_otherdebt_joint==1 | had_ccdebt_own | had_bankloan_own | had_otherdebt_own)
egen DebtAmount = rowtotal(amt_ccdebt_joint amt_bankloan_joint amt_otherdebt_joint amt_ccdebt_own amt_bankloan_own amt_otherdebt_own)
gen AnyCCDebt=(had_ccdebt_joint==1 | had_ccdebt_own==1)
egen CCDebtAmount = rowtotal(amt_ccdebt_joint amt_ccdebt_own)

gen AnyChecking = (had_checking_joint==1 | had_checking_own==1)
egen CheckingAmount = rowtotal(amt_checking_joint amt_checking_own)

egen IntBearAmount = rowtotal (amt_intbear_joint amt_intbear_own)

save WellBeingVars1992_w4, replace
clear



*****************************
** Wave 6, Health Variables
*****************************
quietly infile using sip92t6.dct, using(sipp92t6.dat)
destring pnum, replace

keep id entry pnum tm8800

gen PoorHealth=(tm8800==5)
replace PoorHealth=. if tm8800==0
gen ExcellentHealth=(tm8800==1)
replace ExcellentHealth=. if tm8800==0

rename tm8800 ehltstat
rename id suid 
tostring suid, replace

save WellBeingVars1992_w6, replace
clear



**************************************************************************************************
** 1993
**************************************************************************************************

************
** Wave 3
************


quietly infile using sip93t3.dct, using(sipp93t3.dat)
destring pnum, replace

** NOTE: In 1993 topical modules, the variables id/entry/pnum uniquely identify individuals
** NOTE: The variable id in topical module corresponds to the variable suid in panel data file
** NOTE: Should only use data for a person/month observation if pp_mis for that month is 1.  There are five
**       digits in pp_mis, corresponding to the four reference months of the wave and then the interview month.
keep id entry pnum tm8800 tm9122 pp_mis

gen PoorHealth=(tm8800==5)
replace PoorHealth=. if tm8800==0
gen ExcellentHealth=(tm8800==1)
replace ExcellentHealth=. if tm8800==0

** NOTE: 1993 includes question about days that illness/injury kept person in bed in LAST 4 MONTHS
gen edaysick_last4m=tm9122
recode edaysick_last4m -3=0
drop tm9122

rename tm8800 ehltstat
rename id suid 
tostring suid, replace

save WellBeingVars1993_w3, replace
clear



************
** Wave 6
************
quietly infile using sip93t6.dct, using(sipp93t6.dat)
destring pnum, replace

keep id entry pnum tm9100 tm9322 pp_mis

gen PoorHealth=(tm9100==5)
replace PoorHealth=. if tm9100==0
gen ExcellentHealth=(tm9100==1)
replace ExcellentHealth=. if tm9100==0

** NOTE: 1993 includes question about days that illness/injury kept person in bed in LAST 4 MONTHS
gen edaysick_last4m=tm9322
recode edaysick_last4m -3=0
drop tm9322

rename tm9100 ehltstat
rename id suid 
tostring suid, replace

save WellBeingVars1993_w6, replace
clear


***********************************
** Wave 7: For Debt Variables
***********************************
quietly infile using sip93t7.dct, using(sipp93t7.dat)
destring pnum, replace


gen temp_had_ccdebt_joint = (tm8212==1)
gen temp_amt_ccdebt_joint = tm8214
gen temp_had_bankloan_joint = (tm8216==1)
gen temp_amt_bankloan_joint = tm8218 
gen temp_had_otherdebt_joint = (tm8220==1)
gen temp_amt_otherdebt_joint = tm8222 

gen temp_had_checking_joint = (tm8209==1)
gen temp_amt_checking_joint = tm8210
replace temp_amt_checking_joint = 0 if tm8210==-3



keep id entry pnum pnsp temp_had_ccdebt_joint temp_amt_ccdebt_joint temp_had_bankloan_joint temp_amt_bankloan_joint temp_had_otherdebt_joint temp_amt_otherdebt_joint temp_had_checking_joint temp_amt_checking_joint 

drop pnsp
rename pnum pnsp
rename temp_had_ccdebt_joint sp_had_ccdebt_joint 
rename temp_amt_ccdebt_joint sp_amt_ccdebt_joint
rename temp_had_bankloan_joint sp_had_bankloan_joint
rename temp_amt_bankloan_joint sp_amt_bankloan_joint
rename temp_had_otherdebt_joint sp_had_otherdebt_joint
rename temp_amt_otherdebt_joint sp_amt_otherdebt_joint
rename temp_had_checking_joint sp_had_checking_joint
rename temp_amt_checking_joint sp_amt_checking_joint

save temp, replace
clear


quietly infile using sip93t7.dct, using(sipp93t7.dat)
destring pnum, replace

merge m:1 id entry pnsp using temp
drop if _merge==2


gen had_ccdebt_joint = (tm8212==1 | sp_had_ccdebt_joint==1)
egen amt_ccdebt_joint = rowmean(tm8214 sp_amt_ccdebt_joint)
gen had_bankloan_joint = (tm8216==1 | sp_had_bankloan_joint==1)
egen amt_bankloan_joint = rowmean(tm8218 sp_amt_bankloan_joint) 
gen had_otherdebt_joint = (tm8220==1 | sp_had_otherdebt_joint==1)
egen amt_otherdebt_joint = rowmean(tm8222  sp_amt_otherdebt_joint)

recode tm8210 -3=0
gen had_checking_joint = (tm8209==1 |sp_had_checking_joint==1)
egen amt_checking_joint = rowmean(tm8210  sp_amt_checking_joint)

gen had_ccdebt_own =(tm8236 ==1)
gen amt_ccdebt_own = tm8238
gen had_bankloan_own = (tm8240==1)
gen amt_bankloan_own = tm8242
gen had_otherdebt_own = (tm8244==1)
gen amt_otherdebt_own = tm8246 

gen had_checking_own = (tm8232==1)
gen amt_checking_own = tm8233
replace amt_checking_own = 0 if tm8233==-3




rename id suid 
tostring suid, replace

keep suid entry pnum  had_* amt_* 

gen AnyDebt = (had_ccdebt_joint==1 | had_bankloan_joint==1 | had_otherdebt_joint==1 | had_ccdebt_own | had_bankloan_own | had_otherdebt_own)
egen DebtAmount = rowtotal(amt_ccdebt_joint amt_bankloan_joint amt_otherdebt_joint amt_ccdebt_own amt_bankloan_own amt_otherdebt_own)
gen AnyCCDebt=(had_ccdebt_joint==1 | had_ccdebt_own==1)
egen CCDebtAmount = rowtotal(amt_ccdebt_joint amt_ccdebt_own)

gen AnyChecking = (had_checking_joint==1 | had_checking_own==1)
egen CheckingAmount = rowtotal(amt_checking_joint amt_checking_own)



save WellBeingVars1993_w7, replace
clear



**************************************************************************************************
** 1996
**************************************************************************************************

************
** Wave 3
************

quietly infile using sip96t3.dct, using(sipp96t3.dat)
destring epppnum, replace

keep ssuid epppnum ehltstat edaysick ealil ealidab ealidal ealidao ealidb ealidl ealido ealjdb ealjdl ealjdo ealjdab ealjdal ealjdao esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
gen PoorHealth = (ehltstat==5)
gen ExcellentHealth=(ehltstat==1)

gen split_ealjdab = ealjdab/2
gen split_ealjdal = ealjdal/2
gen split_ealjdao = ealjdao/2

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(ealidab ealidal ealidao split_ealjdab split_ealjdal split_ealjdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(ealidab split_ealjdab)

gen split_taljcha = taljcha/2
gen split_tiajta = tiajta/2

egen AssetAmount = rowtotal(esmiv esmjv talicha split_taljcha talrb talsbv taltb tiaita split_tiajta timia timja)

egen CheckingAmount = rowtotal(talicha split_taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha split_taljcha tiaita split_tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)

save WellBeingVars1996_w3, replace
clear



************
** Wave 6
************

quietly infile using sip96t6.dct, using(sipp96t6.dat)
destring epppnum, replace


keep ssuid epppnum ehltstat edaysick ealil ealidab ealidal ealidao ealidb ealidl ealido ealjdb ealjdl ealjdo ealjdab ealjdal ealjdao esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
gen PoorHealth = (ehltstat==5)
gen ExcellentHealth=(ehltstat==1)

gen split_ealjdab = ealjdab/2
gen split_ealjdal = ealjdal/2
gen split_ealjdao = ealjdao/2

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(ealidab ealidal ealidao split_ealjdab split_ealjdal split_ealjdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(ealidab split_ealjdab)

gen split_taljcha = taljcha/2
gen split_tiajta = tiajta/2

egen AssetAmount = rowtotal(esmiv esmjv talicha split_taljcha talrb talsbv taltb tiaita split_tiajta timia timja)

egen CheckingAmount = rowtotal(talicha split_taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha split_taljcha tiaita split_tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)


save WellBeingVars1996_w6, replace
clear



************
** Wave 9
************

quietly infile using sip96t9.dct, using(sipp96t9.dat)
destring epppnum, replace


keep ssuid epppnum ehltstat edaysick ealil ealidab ealidal ealidao ealidb ealidl ealido ealjdb ealjdl ealjdo ealjdab ealjdal ealjdao esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
gen PoorHealth = (ehltstat==5)
gen ExcellentHealth=(ehltstat==1)

gen split_ealjdab = ealjdab/2
gen split_ealjdal = ealjdal/2
gen split_ealjdao = ealjdao/2

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(ealidab ealidal ealidao split_ealjdab split_ealjdal split_ealjdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(ealidab split_ealjdab)

gen split_taljcha = taljcha/2
gen split_tiajta = tiajta/2

egen AssetAmount = rowtotal(esmiv esmjv talicha split_taljcha talrb talsbv taltb tiaita split_tiajta timia timja)

egen CheckingAmount = rowtotal(talicha split_taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha split_taljcha tiaita split_tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)


save WellBeingVars1996_w9, replace
clear



************
** Wave 12
************

quietly infile using sip96t12.dct, using(sipp96t12.dat)
destring epppnum, replace


keep ssuid epppnum ehltstat edaysick ealil ealidab ealidal ealidao ealidb ealidl ealido ealjdb ealjdl ealjdo ealjdab ealjdal ealjdao esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
gen PoorHealth = (ehltstat==5)
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(ealidab ealidal ealidao ealjdab ealjdal ealjdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(ealidab ealjdab)

gen split_taljcha = taljcha/2
gen split_tiajta = tiajta/2

egen AssetAmount = rowtotal(esmiv esmjv talicha split_taljcha talrb talsbv taltb tiaita split_tiajta timia timja)

egen CheckingAmount = rowtotal(talicha split_taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha split_taljcha tiaita split_tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)


save WellBeingVars1996_w12, replace
clear



**************************************************************************************************
** 2001
**************************************************************************************************

************
** Wave 3
************

quietly infile using sip01t3.dct, using(sipp01t3.dat)
destring epppnum, replace

keep ssuid epppnum ehltstat edaysick ealil ealidab ealidal ealidao ealidb ealidl ealido ealjdb ealjdl ealjdo ealjdab ealjdal ealjdao esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
gen PoorHealth = (ehltstat==5)
gen ExcellentHealth=(ehltstat==1)

**NOTE: No need to split joint amounts across spouses, as the SIPP processing has already done that.

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(ealidab ealidal ealidao ealjdab ealjdal ealjdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(ealidab ealjdab)

egen AssetAmount = rowtotal(esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja)


egen CheckingAmount = rowtotal(talicha taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha taljcha tiaita tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)


save WellBeingVars2001_w3, replace
clear



************
** Wave 6
************

quietly infile using sip01t6.dct, using(sipp01t6.dat)
destring epppnum, replace

keep ssuid epppnum ehltstat edaysick ealil ealidab ealidal ealidao ealidb ealidl ealido ealjdb ealjdl ealjdo ealjdab ealjdal ealjdao esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
gen PoorHealth = (ehltstat==5)
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(ealidab ealidal ealidao ealjdab ealjdal ealjdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(ealidab ealjdab)

egen AssetAmount = rowtotal(esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja)


egen CheckingAmount = rowtotal(talicha taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha taljcha tiaita tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)


save WellBeingVars2001_w6, replace
clear



************
** Wave 9
************

quietly infile using sip01t9.dct, using(sipp01t9.dat)
destring epppnum, replace

keep ssuid epppnum ehltstat edaysick ealil ealidab ealidal ealidao ealidb ealidl ealido ealjdb ealjdl ealjdo ealjdab ealjdal ealjdao esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
gen PoorHealth = (ehltstat==5)
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(ealidab ealidal ealidao ealjdab ealjdal ealjdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(ealidab ealjdab)

egen AssetAmount = rowtotal(esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja)


egen CheckingAmount = rowtotal(talicha taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha taljcha tiaita tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)


save WellBeingVars2001_w9, replace
clear




**************************************************************************************************
** 2004
**************************************************************************************************

************
** Wave 3
************

quietly infile using sip04t3.dct, using(p04putm3.dat)
destring epppnum, replace

keep ssuid epppnum ehltstat edaysick ealil ealidab ealidal ealidao ealidb ealidl ealido ealjdb ealjdl ealjdo ealjdab ealjdal ealjdao esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
gen PoorHealth = (ehltstat==5)
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(ealidab ealidal ealidao ealjdab ealjdal ealjdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(ealidab ealjdab)

egen AssetAmount = rowtotal(esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja)


egen CheckingAmount = rowtotal(talicha taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha taljcha tiaita tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)

save WellBeingVars2004_w3, replace
clear



************
** Wave 6
************

quietly infile using sip04t6.dct, using(p04putm6.dat)
destring epppnum, replace

keep ssuid epppnum ehltstat edaysick ealil ealidab ealidal ealidao ealidb ealidl ealido ealjdb ealjdl ealjdo ealjdab ealjdal ealjdao esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
gen PoorHealth = (ehltstat==5)
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(ealidab ealidal ealidao ealjdab ealjdal ealjdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(ealidab ealjdab)

egen AssetAmount = rowtotal(esmiv esmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja)


egen CheckingAmount = rowtotal(talicha taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha taljcha tiaita tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)

save WellBeingVars2004_w6, replace
clear



**************************************************************************************************
** 2008
**************************************************************************************************

************
** Wave 4
************

quietly infile using sippp08putm4.dct, using(p08putm4.dat)
destring epppnum, replace

keep ssuid epppnum ehltstat edaysick ealil ealidb ealidl ealido talidab talidal talidao ealjdb ealjdl ealjdo taljdab taljdal taljdao tsmiv tsmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
** NOTE: ealil = Had any debts in own name (1==yes)
** ealidb = Owed any money in own name on store bills or credit cards (talidab)
** ealidl = Owed any money in own name on bank loans other than car or home equity (talidal)
** ealido = Owed any money in own name on other types of debt (talidao)
** ealjdb = Owed any money joint with spouse on store bills or credit cards ($ amt = taljdab)
** ealjdl = Owed any money joint with spouse on bank loans ($ amt = taljdal)
** ealjdo = Owed any money joint with spouse on other types of debt ($ amt = taljdao)

gen PoorHealth = (ehltstat==5) 
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(talidab talidal talidao taljdab taljdal taljdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(talidab taljdab)

egen AssetAmount = rowtotal(tsmiv tsmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja)


egen CheckingAmount = rowtotal(talicha taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha taljcha tiaita tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)

save WellBeingVars2008_w4, replace
clear

************
** Wave 7
************

quietly infile using sippp08putm7.dct, using(p08putm7.dat)
destring epppnum, replace

keep ssuid epppnum ehltstat edaysick ealil ealidb ealidl ealido talidab talidal talidao ealjdb ealjdl ealjdo taljdab taljdal taljdao tsmiv tsmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
** NOTE: ealil = Had any debts in own name (1==yes)
** ealidb = Owed any money in own name on store bills or credit cards (talidab)
** ealidl = Owed any money in own name on bank loans other than car or home equity (talidal)
** ealido = Owed any money in own name on other types of debt (talidao)
** ealjdb = Owed any money joint with spouse on store bills or credit cards ($ amt = taljdab)
** ealjdl = Owed any money joint with spouse on bank loans ($ amt = taljdal)
** ealjdo = Owed any money joint with spouse on other types of debt ($ amt = taljdao)

gen PoorHealth = (ehltstat==5) 
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(talidab talidal talidao taljdab taljdal taljdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(talidab taljdab)

egen AssetAmount = rowtotal(tsmiv tsmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja)


egen CheckingAmount = rowtotal(talicha taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha taljcha tiaita tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)

save WellBeingVars2008_w7, replace
clear

************
** Wave 10
************

quietly infile using sippp08putm10.dct, using(p08putm10.dat)
destring epppnum, replace

keep ssuid epppnum ehltstat edaysick ealil ealidb ealidl ealido talidab talidal talidao ealjdb ealjdl ealjdo taljdab taljdal taljdao tsmiv tsmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja
** NOTE: ealil = Had any debts in own name (1==yes)
** ealidb = Owed any money in own name on store bills or credit cards (talidab)
** ealidl = Owed any money in own name on bank loans other than car or home equity (talidal)
** ealido = Owed any money in own name on other types of debt (talidao)
** ealjdb = Owed any money joint with spouse on store bills or credit cards ($ amt = taljdab)
** ealjdl = Owed any money joint with spouse on bank loans ($ amt = taljdal)
** ealjdo = Owed any money joint with spouse on other types of debt ($ amt = taljdao)

gen PoorHealth = (ehltstat==5) 
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (ealil==1 | ealidb==1 | ealidl==1 | ealido==1 | ealjdb==1 | ealjdl==1 | ealjdo==1)
egen DebtAmount = rowtotal(talidab talidal talidao taljdab taljdal taljdao)
gen AnyCCDebt = (ealidb==1 | ealjdb==1)
egen CCDebtAmount = rowtotal(talidab taljdab)

egen AssetAmount = rowtotal(tsmiv tsmjv talicha taljcha talrb talsbv taltb tiaita tiajta timia timja)


egen CheckingAmount = rowtotal(talicha taljcha)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(talicha taljcha tiaita tiajta)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)


save WellBeingVars2008_w10, replace



**************************************************************************************************
** 2014
**************************************************************************************************

************
** Wave 1
************

use ssuid pnum spanel swave monthcode ehltstat tdaysick edebt_cc tdebt_cc edebt_ed tdebt_ed edebt_ot tdebt_ot tomfval tostval tjsmfval tjsstval tochkval tjschkval tirakeoval togovsval tthr401val tocdval tjscdval toichkval tjsichkval tommval tjsmmval tosavval tjssavval tjsgovsval tjsmcbdval using pu2014w1.dta

** Debt variables for 2014
** edebt_cc = Owed any money on credit cards or store bills
** tdebt_cc = Person-level sum of amt owed on credit card debt and store bills
** edebt_ed = Owed any money for student loans or educational-related expenses
** tdebt_ed = Person-level sum of value of education debt
** edebt_ot = owed any money on other debts (medical bills, bank loans, owed to private individuals)
** tdebt_ot = Person-level sum of amount owed on other debts


gen PoorHealth = (ehltstat==5) 
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (edebt_cc==1 | edebt_ed==1 | edebt_ot==1)
egen DebtAmount = rowtotal(tdebt_cc tdebt_ed tdebt_ot)
gen AnyCCDebt = (edebt_cc==1 )
gen CCDebtAmount = tdebt_cc


** Asset variables
** What previously was in tsmiv and tsmjv is now in:
**	tomfval = Value of individually-owned mutual funds
**  tostval = Value of individually-owned stocks
**  tjsmfval = Own portion of jointly-owned mutual funds
**  tjsstval = Own portion of jointly-owned stocks
** What was previously in talicha and taljcha is now in
**  tochkval = Value of individually-owned regular checking account
**  tjschkval = Own portion of jointly-owned checking account
** IRA value questions previously in talrb now
**   tirakeoval = Value of IRA and Keogh accounts
** Savings bond question previously in talsbv now
**   togovsval = Value of individually-owned govt bonds
** Market value of 401k, 403b, or thrift plan previously in taltb now
**   tthr401val 
** Amount in interest-earning accounts used to be lumped into tiaita and tiajta,
** but now it is split across several different types of interest-earning accounts
**   tocdval, tjscdval (CDs)
**   toichkval, tjsichkval (checking accounts, interest bearing)
**   tommval, tjsmmval (money markets)
**   tosavval, tjssavval (savings accounts, interest bearing)
** Info in previous bond question timja now in two
**    tjsgovsval
**    tjsmcbdval

egen AssetAmount = rowtotal(tomfval tostval tjsmfval tjsstval tochkval tjschkval tirakeoval togovsval tthr401val tocdval tjscdval toichkval tjsichkval tommval tjsmmval tosavval tjssavval tjsgovsval tjsmcbdval)


egen CheckingAmount = rowtotal(tochkval tjschkval toichkval tjsichkval)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(tosavval tjssavval tochkval tjschkval toichkval tjsichkval)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)

save WellBeingVars2014_w1, replace
clear




************
** Wave 2
************

use ssuid pnum spanel swave monthcode ehltstat tdaysick edebt_cc tdebt_cc edebt_ed tdebt_ed edebt_ot tdebt_ot tomfval tostval tjsmfval tjsstval tochkval tjschkval tirakeoval togovsval tthr401val tocdval tjscdval toichkval tjsichkval tommval tjsmmval tosavval tjssavval tjsgovsval tjsmcbdval using pu2014w2.dta

** Debt variables for 2014
** edebt_cc = Owed any money on credit cards or store bills
** tdebt_cc = Person-level sum of amt owed on credit card debt and store bills
** edebt_ed = Owed any money for student loans or educational-related expenses
** tdebt_ed = Person-level sum of value of education debt
** edebt_ot = owed any money on other debts (medical bills, bank loans, owed to private individuals)
** tdebt_ot = Person-level sum of amount owed on other debts


gen PoorHealth = (ehltstat==5) 
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (edebt_cc==1 | edebt_ed==1 | edebt_ot==1)
egen DebtAmount = rowtotal(tdebt_cc tdebt_ed tdebt_ot)
gen AnyCCDebt = (edebt_cc==1 )
gen CCDebtAmount = tdebt_cc


** Asset variables
** What previously was in tsmiv and tsmjv is now in:
**	tomfval = Value of individually-owned mutual funds
**  tostval = Value of individually-owned stocks
**  tjsmfval = Own portion of jointly-owned mutual funds
**  tjsstval = Own portion of jointly-owned stocks
** What was previously in talicha and taljcha is now in
**  tochkval = Value of individually-owned regular checking account
**  tjschkval = Own portion of jointly-owned checking account
** IRA value questions previously in talrb now
**   tirakeoval = Value of IRA and Keogh accounts
** Savings bond question previously in talsbv now
**   togovsval = Value of individually-owned govt bonds
** Market value of 401k, 403b, or thrift plan previously in taltb now
**   tthr401val 
** Amount in interest-earning accounts used to be lumped into tiaita and tiajta,
** but now it is split across several different types of interest-earning accounts
**   tocdval, tjscdval (CDs)
**   toichkval, tjsichkval (checking accounts, interest bearing)
**   tommval, tjsmmval (money markets)
**   tosavval, tjssavval (savings accounts, interest bearing)
** Info in previous bond question timja now in two
**    tjsgovsval
**    tjsmcbdval

egen AssetAmount = rowtotal(tomfval tostval tjsmfval tjsstval tochkval tjschkval tirakeoval togovsval tthr401val tocdval tjscdval toichkval tjsichkval tommval tjsmmval tosavval tjssavval tjsgovsval tjsmcbdval)


egen CheckingAmount = rowtotal(tochkval tjschkval toichkval tjsichkval)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(tosavval tjssavval tochkval tjschkval toichkval tjsichkval)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)

save WellBeingVars2014_w2, replace
clear





************
** Wave 3
************

use ssuid pnum spanel swave monthcode ehltstat tdaysick edebt_cc tdebt_cc edebt_ed tdebt_ed edebt_ot tdebt_ot tomfval tostval tjsmfval tjsstval tochkval tjschkval tirakeoval togovsval tthr401val tocdval tjscdval toichkval tjsichkval tommval tjsmmval tosavval tjssavval tjsgovsval tjsmcbdval using pu2014w3_13.dta

** Debt variables for 2014
** edebt_cc = Owed any money on credit cards or store bills
** tdebt_cc = Person-level sum of amt owed on credit card debt and store bills
** edebt_ed = Owed any money for student loans or educational-related expenses
** tdebt_ed = Person-level sum of value of education debt
** edebt_ot = owed any money on other debts (medical bills, bank loans, owed to private individuals)
** tdebt_ot = Person-level sum of amount owed on other debts


gen PoorHealth = (ehltstat==5) 
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (edebt_cc==1 | edebt_ed==1 | edebt_ot==1)
egen DebtAmount = rowtotal(tdebt_cc tdebt_ed tdebt_ot)
gen AnyCCDebt = (edebt_cc==1 )
gen CCDebtAmount = tdebt_cc



egen AssetAmount = rowtotal(tomfval tostval tjsmfval tjsstval tochkval tjschkval tirakeoval togovsval tthr401val tocdval tjscdval toichkval tjsichkval tommval tjsmmval tosavval tjssavval tjsgovsval tjsmcbdval)


egen CheckingAmount = rowtotal(tochkval tjschkval toichkval tjsichkval)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(tosavval tjssavval tochkval tjschkval toichkval tjsichkval)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)

save WellBeingVars2014_w3, replace
clear




************
** Wave 4
************

use ssuid pnum spanel swave monthcode ehltstat tdaysick edebt_cc tdebt_cc edebt_ed tdebt_ed edebt_ot tdebt_ot tomfval tostval tjsmfval tjsstval tochkval tjschkval tirakeoval togovsval tthr401val tocdval tjscdval toichkval tjsichkval tommval tjsmmval tosavval tjssavval tjsgovsval tjsmcbdval using pu2014w4.dta

** Debt variables for 2014
** edebt_cc = Owed any money on credit cards or store bills
** tdebt_cc = Person-level sum of amt owed on credit card debt and store bills
** edebt_ed = Owed any money for student loans or educational-related expenses
** tdebt_ed = Person-level sum of value of education debt
** edebt_ot = owed any money on other debts (medical bills, bank loans, owed to private individuals)
** tdebt_ot = Person-level sum of amount owed on other debts


gen PoorHealth = (ehltstat==5) 
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (edebt_cc==1 | edebt_ed==1 | edebt_ot==1)
egen DebtAmount = rowtotal(tdebt_cc tdebt_ed tdebt_ot)
gen AnyCCDebt = (edebt_cc==1 )
gen CCDebtAmount = tdebt_cc



egen AssetAmount = rowtotal(tomfval tostval tjsmfval tjsstval tochkval tjschkval tirakeoval togovsval tthr401val tocdval tjscdval toichkval tjsichkval tommval tjsmmval tosavval tjssavval tjsgovsval tjsmcbdval)


egen CheckingAmount = rowtotal(tochkval tjschkval toichkval tjsichkval)
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(tosavval tjssavval tochkval tjschkval toichkval tjsichkval)
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)

save WellBeingVars2014_w4, replace
clear




********************************************************************************
****************
** 2018 Panel
****************
********************************************************************************

use ssuid pnum spanel swave monthcode ehltstat tdaysick edebt_cc tdebt_cc edebt_ed tdebt_ed edebt_ot tdebt_ot edebt_med tmed_amt tomfval tostval tjsmfval tjsstval tochkval tjschkval tirakeoval togovsval tthr401val tocdval tjscdval  tommval tjsmmval tosavval tjssavval tjsgovsval tjsmcbdval using pu2018.dta

** Debt variables for 2014
** edebt_cc = Owed any money on credit cards or store bills
** tdebt_cc = Person-level sum of amt owed on credit card debt and store bills
** edebt_ed = Owed any money for student loans or educational-related expenses
** tdebt_ed = Person-level sum of value of education debt
** edebt_ot = owed any money on other debts (medical bills, bank loans, owed to private individuals)
** tdebt_ot = Person-level sum of amount owed on other debts


gen PoorHealth = (ehltstat==5) 
gen ExcellentHealth=(ehltstat==1)

gen AnyDebt = (edebt_cc==1 | edebt_ed==1 | edebt_ot==1 | edebt_med==1)
egen DebtAmount = rowtotal(tdebt_cc tdebt_ed tdebt_ot tmed_amt)
gen AnyCCDebt = (edebt_cc==1 )
gen CCDebtAmount = tdebt_cc



egen AssetAmount = rowtotal(tomfval tostval tjsmfval tjsstval tochkval tjschkval tirakeoval togovsval tthr401val tocdval tjscdval  tommval tjsmmval tosavval tjssavval tjsgovsval tjsmcbdval)


egen CheckingAmount = rowtotal(tochkval tjschkval )
replace CheckingAmount = 0 if CheckingAmount<0
gen AnyChecking = (CheckingAmount>0)

egen SavingsCheckingAmount = rowtotal(tosavval tjssavval tochkval tjschkval )
replace SavingsCheckingAmount = 0 if SavingsCheckingAmount<0
gen AnySavingsChecking = (SavingsCheckingAmount>0)

save WellBeingVars2018_w1, replace
clear




**********************************************************************
**********************************************************************
** FERTILITY HISTORY VARIABLES
**********************************************************************
**********************************************************************


**********************
** 1990, Wave 2
**********************


quietly infile using sip90t2.dct, using(s90w2tm.dat)
destring pnum, replace

keep id entry pnum tm8750 tm8752 tm8754 tm8758 tm8778

gen FH_N_KidsEverBorn = .
** Use female version of "kids ever born" for women
replace FH_N_KidsEverBorn = tm8754 if tm8750==1
recode FH_N_KidsEverBorn -3=0
** Use male version of "kids ever born" for men ages 18+
replace FH_N_KidsEverBorn = tm8752 if tm8750==2
recode FH_N_KidsEverBorn -3=0
recode FH_N_KidsEverBorn -1=0

rename id suid 
tostring suid, replace

save FertilityHistoryVars1990_w2, replace
clear




**********************
** 1991, Wave 2
**********************


quietly infile using sip91t2.dct, using(sipp91t2.dat)
destring pnum, replace

keep id entry pnum tm8750 tm8752 tm8754 tm8758 tm8778

gen FH_N_KidsEverBorn = .
** Use female version of "kids ever born" for women
replace FH_N_KidsEverBorn = tm8754 if tm8750==1
recode FH_N_KidsEverBorn -3=0
** Use male version of "kids ever born" for men ages 18+
replace FH_N_KidsEverBorn = tm8752 if tm8750==2
recode FH_N_KidsEverBorn -3=0
recode FH_N_KidsEverBorn -1=0

rename id suid 
tostring suid, replace

save FertilityHistoryVars1991_w2, replace
clear




**********************
** 1992, Wave 2
**********************

quietly infile using sip92t2.dct, using(sipp92t2.dat)
destring pnum, replace

keep id entry pnum tm8750 tm8752 tm8754 tm8758 tm8778

gen FH_N_KidsEverBorn = .
** Use female version of "kids ever born" for women
replace FH_N_KidsEverBorn = tm8754 if tm8750==1
recode FH_N_KidsEverBorn -3=0
** Use male version of "kids ever born" for men ages 18+
replace FH_N_KidsEverBorn = tm8752 if tm8750==2
recode FH_N_KidsEverBorn -3=0
recode FH_N_KidsEverBorn -1=0

rename id suid 
tostring suid, replace

save FertilityHistoryVars1992_w2, replace
clear


**********************
** 1993, Wave 2
**********************


quietly infile using sip93t2.dct, using(sipp93t2.dat)
destring pnum, replace

keep id entry pnum tm8750 tm8752 tm8754 tm8758 tm8778

gen FH_N_KidsEverBorn = .
** Use female version of "kids ever born" for women
replace FH_N_KidsEverBorn = tm8754 if tm8750==1
recode FH_N_KidsEverBorn -3=0
** Use male version of "kids ever born" for men ages 18+
replace FH_N_KidsEverBorn = tm8752 if tm8750==2
recode FH_N_KidsEverBorn -3=0
recode FH_N_KidsEverBorn -1=0

rename id suid 
tostring suid, replace

save FertilityHistoryVars1993_w2, replace
clear



**********************
** 1996, Wave 2
**********************
** NOTE: The tmomchl and tfrchl variables are in here, but egrndpr is not
** Also note that universe for tmomchl is only women 15-64, but universe for tfrchl seems to be men age 15+

quietly infile using sip96t2.dct, using(sipp96t2.dat)
destring epppnum, replace

keep ssuid epppnum tmomchl tfrchl 

gen FH_N_KidsEverBorn = .
replace FH_N_KidsEverBorn = tmomchl if tmomchl~=-1
replace FH_N_KidsEverBorn = tfrchl if FH_N_KidsEverBorn==. & tfrchl~=-1

save FertilityHistoryVars1996_w2, replace
clear



**********************
** 2001, Wave 2
**********************

quietly infile using sip01t2.dct, using(sipp01t2.dat)
destring epppnum, replace

keep ssuid epppnum tmomchl tfrchl egrndpr

gen FH_N_KidsEverBorn = .
replace FH_N_KidsEverBorn = tmomchl if tmomchl~=-1
replace FH_N_KidsEverBorn = tfrchl if FH_N_KidsEverBorn==. & tfrchl~=-1

gen FH_grandparent = (egrndpr==1)

save FertilityHistoryVars2001_w2, replace
clear




**********************
** 2004, Wave 2
**********************

quietly infile using sippp04putm2.dct, using(p04putm2.dat)
destring epppnum, replace

keep ssuid epppnum tmomchl tfrchl egrndpr

gen FH_N_KidsEverBorn = .
replace FH_N_KidsEverBorn = tmomchl if tmomchl~=-1
replace FH_N_KidsEverBorn = tfrchl if FH_N_KidsEverBorn==. & tfrchl~=-1

gen FH_grandparent = (egrndpr==1)

save FertilityHistoryVars2004_w2, replace
clear


**********************
** 2008, Wave 2
**********************

quietly infile using sippp08putm2.dct, using(p08putm2.dat)
destring epppnum, replace

keep ssuid epppnum tmomchl tfrchl egrndpr

gen FH_N_KidsEverBorn = .
replace FH_N_KidsEverBorn = tmomchl if tmomchl~=-1
replace FH_N_KidsEverBorn = tfrchl if FH_N_KidsEverBorn==. & tfrchl~=-1

gen FH_grandparent = (egrndpr==1)

save FertilityHistoryVars2008_w2, replace
clear



**********************
** 2014, Wave 1
**********************

use ssuid pnum spanel swave tceb egrndpr using pu2014w1.dta

gen FH_N_KidsEverBorn = tceb

gen FH_grandparent = (egrndpr==1)

count
** Don't need to keep multiple months
duplicates drop
count

save FertilityHistoryVars2014_w1, replace
clear




**********************
** 2014, Wave 2
**********************

use ssuid pnum spanel swave tceb egrndpr using pu2014w2.dta

gen FH_N_KidsEverBorn = tceb

gen FH_grandparent = (egrndpr==1)

count
** Don't need to keep multiple months
duplicates drop
count

save FertilityHistoryVars2014_w2, replace
clear



**********************
** 2014, Wave 3
**********************

use ssuid pnum spanel swave tceb egrndpr using pu2014w3_13.dta

gen FH_N_KidsEverBorn = tceb

gen FH_grandparent = (egrndpr==1)

count
** Don't need to keep multiple months
duplicates drop
count

save FertilityHistoryVars2014_w3, replace
clear




**********************
** 2014, Wave 4
**********************

use ssuid pnum spanel swave tceb egrndpr using pu2014w4.dta

gen FH_N_KidsEverBorn = tceb

gen FH_grandparent = (egrndpr==1)

count
** Don't need to keep multiple months
duplicates drop
count

save FertilityHistoryVars2014_w4, replace
clear




